package br.com.foxinline.conversor;

import br.com.foxinline.modelo.TipoDeficiencia;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author laverson
 */
@FacesConverter(value = "tipodeficienciaconverter", forClass=TipoDeficiencia.class)
public class TipoDeficienciaConverter implements Converter{
    
    @Override
    public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
        if (value != null && !value.isEmpty()) {
            return (TipoDeficiencia) uiComponent.getAttributes().get(value);
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
        if (value instanceof TipoDeficiencia) {
            TipoDeficiencia entity= (TipoDeficiencia) value;
            if (entity != null && entity instanceof TipoDeficiencia && entity.getId() != null) {
                uiComponent.getAttributes().put( entity.getId().toString(), entity);
                return entity.getId().toString();
            }
        }
        return "";
    }
}